package chapter11;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @create 2018-03-23 上午9:56
 */
public class PrintUtilTest {
    private static final Logger LOGGER = LoggerFactory.getLogger(PrintUtilTest.class);

    public static void main(String[] args) {
        File file = new File(File.separator + "home" + File.separator + "lzy" + File.separator + "logs" + File.separator + "test" + File.separator + "test.dat");
        try (OutputStream outStream = new FileOutputStream(file)) {
            PrintUtil pu = new PrintUtil(outStream);
            pu.println("www.yook.com");
            pu.println(1 + 1);
            pu.println(1.1 + 1.1);
            pu.println("测试数据");

            PrintStream printStream = new PrintStream(outStream);

            printStream.println("\n");
            printStream.println("this is print by printStream.");
            printStream.println(1 + 1);
            printStream.println(1.1 + 2.3);
            printStream.println(new Date());
            printStream.println(LocalDateTime.now());

            String name = "小王";
            int age = 22;
            double score = 59.324324234;
            printStream.printf("name:%s, age:%d, score:%8.5f", name, age, score);
            System.err.printf("name:%s, age:%d, score:%8.5f", name, age, score);
        } catch (IOException e) {
            e.printStackTrace();
        }

        java.util.function.Consumer<String> consumer = System.out::println;
        consumer.accept("this is a function reference");
    }
}
